package com.moli.iov.base.remote.impl;

import com.moli.iov.base.remote.IVehicleFollowGroupRemoteService;
import com.moli.iov.base.remote.InitCacheRemoteService;
import com.moli.iov.base.service.*;
import com.moli.iov.rest.RestResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 初始化数据缓存
 *
 * @author wanghualin
 * @date 2019 -10-22 15:32:56
 */
@Slf4j
@Service(group = "${service.group}")
public class InitCacheRemoteServiceImpl implements InitCacheRemoteService {
  private static final long serialVersionUID = 1L;
  @Autowired
  private ICompanyVehicleModelService iCompanyVehicleModelService;
  @Autowired
  private IDictDataService iDictDataService;
  @Autowired
  private IVehicleTboxService iVehicleTboxService;
  @Autowired
  private IVehicleBaseService iVehicleBaseService;
  @Autowired
  private IVehicleAttentionService iVehicleAttentionService;
  @Autowired
  private IVehicleFenceService iVehicleFenceService;
  @Autowired
  private IVehicleFenceBindingService iVehicleFenceBindingService;
  @Autowired
  private ISysParamSettingsService settingsService;
  @Autowired
  private IBaseCityService iBaseCityService;
  @Autowired
  private IVehicleBaseAuthService baseAuthService;
  @Autowired
  private IVehicleFollowGroupService iVehicleFollowGroupService;

  @Override
  public RestResponse initCache() {
    try {
      log.info("================>自动加载启动开始");
      long l = System.currentTimeMillis();
      iDictDataService.cacheAllDict();
      settingsService.initSysParamSettings();
      iCompanyVehicleModelService.initCompanyVehicleModel();
      iVehicleTboxService.initVehicleTbox();
      iVehicleBaseService.initVehicleBase();
      baseAuthService.initVehicleVehicleBaseAuth();
      iVehicleAttentionService.initVehicleAttention();
      iVehicleFenceBindingService.initVehicleFenceBinding();
      iVehicleFenceService.initVehicleFence();
      iBaseCityService.initCityCache();
      iVehicleFollowGroupService.init();
      long l2 = System.currentTimeMillis();
      long a = l2 - l;
      log.info("================>自动加载启动成功" + a);
      log.info("================>自动加载启动成功");
      return RestResponse.success();
    } catch (Exception e) {
      e.printStackTrace();
      log.info("自动加载失败：" + e.getMessage());
      return RestResponse.failure("自动加载失败");
    }
  }
}
